package newtank.view;

import entity.Bullet;
import entity.Direction;
import entity.MoveGenerator;
import entity.Position;
import newtank.view.context.BulletViewContext;

import java.awt.*;

/**
 * 子弹视图
 * @author lijiahao
 */
public class BulletView implements PaintView {

	private final BulletViewContext bulletViewContext;

	private final String unique;

	public BulletView(BulletViewContext bulletViewContext) {
		this.bulletViewContext = bulletViewContext;
		this.unique = bulletViewContext.getUnique();
	}

	@Override
	public void draw(Graphics2D g2d) {
		drawShoot(g2d);
	}

	@Override
	public String getIdentity() {
		return unique;
	}

	@Override
	public void move() {
		MoveGenerator.move(bulletViewContext.getPosition(), bulletViewContext.getDirection(), bulletViewContext.getSpeed(), this.getClass());
	}

	@Override
	public void turnLeft() {
		bulletViewContext.setDirection(Direction.LEFT);
	}

	@Override
	public void turnRight() {
		bulletViewContext.setDirection(Direction.RIGHT);
	}

	@Override
	public void turnDown() {
		bulletViewContext.setDirection(Direction.DOWN);
	}

	@Override
	public void turnUp() {bulletViewContext.setDirection(Direction.UP); }

	private void drawShoot(Graphics2D g2d) {
		Position position = bulletViewContext.getPosition();
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setColor(Color.WHITE);
		g2d.fillArc(position.getX(), position.getY(), Bullet.Round, Bullet.Round, 0, 360);
	}
}
